﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ASPNETMVCApplication.ActionServiceReference;
using ASPNETMVCApplication.Repositories.Core;

namespace ASPNETMVCApplication.Repositories
{
    /// <summary>
    ///
    /// </summary>
    public class PointRepository : RepositoryBase, IPointRepository
    {
        /// <summary>
        /// Returns an order by orderId.
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public Point Get(int pointId)
        {
           return null;
        }

           
       public void Insert(Point point)
        {

            var request = new  PointRequest().Prepare();
            request.Action = "Create";
            request.Point = point;
            //request.ChairList = ChairList.ToArray();

            var response = Client.SetPoints(request);

            Correlate(request, response);

            // These messages are for public consumption. Includes validation errors.
            if (response.Acknowledge == AcknowledgeType.Failure)
                throw new ApplicationException(response.Message);

        }

  
        public List<Point> GetPointList(int provinceId, string sort, string order)
        {
            var request = new PointRequest().Prepare();

            request.LoadOptions = new string[] { "Points" };
            request.Criteria = new PointCriteria
            {
                ProvinceId = provinceId,
                SortExpression = sort + " " + order,
            };

            var response = Client.GetPoints(request);

            Correlate(request, response);

            return response.Points == null ? null : response.Points.ToList();
        }

        public void Update(Point point)
        {
            var request = new PointRequest().Prepare();
            request.Action = "Update";
            request.Point = point;

            var response = Client.SetPoints(request);

            Correlate(request, response);

            // These messages are for public consumption. Includes validation errors.
            if (response.Acknowledge == AcknowledgeType.Failure)
                throw new ApplicationException(response.Message);
        }

        
        #region Not implemented members

        public List<ActionServiceReference.Point> GetList(Criterion criterion = null)
        {
            throw new NotImplementedException();
        }

        public ActionServiceReference.Point Get(Criterion criterion = null)
        {
            throw new NotImplementedException();
        }

        public int GetCount(Criterion criterion = null)
        {
            throw new NotImplementedException();
        }
        public void Delete(int id)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}